//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package gitee_triger

import (
	"fmt"
	"testing"
)

const _ISSUE_HOOK_DATA = `
{
  "iid": "I1EL99",
  "url": "https://gitee.com/oschina/git-osc/issues/I1EL99",
  "sign": "",
  "user": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "email": "gitee@gitee.com",
    "username": "oschina-org",
    "user_name": "oschina-org"
  },
  "issue": {
    "id": 295024870,
    "body": "这是一条测试 WebHook 接收功能触发的推送",
    "user": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "state": "open",
    "title": "这是一条测试 WebHook 接收功能触发的推送",
    "labels": [
      {
        "id": 827033694,
        "name": "bug",
        "color": "d73a4a"
      }
    ],
    "number": "I1EL99",
    "assignee": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "comments": 0,
    "html_url": "https://gitee.com/oschina/git-osc/issues/I1EL99",
    "milestone": {
      "id": 1,
      "state": "open",
      "title": "问题反馈",
      "number": 1,
      "html_url": "https://gitee.com/oschina/gitee/milestones/14143",
      "created_at": "2020-04-15T21:09:40+08:00",
      "updated_at": "2020-04-15T21:09:40+08:00",
      "open_issues": 13,
      "closed_issues": 31
    },
    "type_name": "任务",
    "created_at": "2020-04-15T21:09:40+08:00",
    "state_name": "待办的",
    "updated_at": "2020-04-15T21:09:40+08:00",
    "collaborators": [
      {
        "id": 1,
        "url": "https://gitee.com/oschina-org",
        "name": "Gitee",
        "time": "2020-04-15T21:09:40+08:00",
        "type": "User",
        "email": "gitee@gitee.com",
        "login": "oschina-org",
        "html_url": "https://gitee.com/oschina-org",
        "username": "oschina-org",
        "user_name": "oschina-org",
        "avatar_url": "https://gitee.com/assets/favicon.ico",
        "site_admin": false
      }
    ]
  },
  "state": "open",
  "title": "这是一条测试 WebHook 接收功能触发的推送",
  "action": "open",
  "sender": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "time": "2020-04-15T21:09:40+08:00",
    "type": "User",
    "email": "gitee@gitee.com",
    "login": "oschina-org",
    "html_url": "https://gitee.com/oschina-org",
    "username": "oschina-org",
    "user_name": "oschina-org",
    "avatar_url": "https://gitee.com/assets/favicon.ico",
    "site_admin": false
  },
  "hook_id": 1457589,
  "project": {
    "id": 151,
    "url": "https://gitee.com/oschina/git-osc",
    "fork": false,
    "name": "Gitee FeedBack",
    "path": "git-osc",
    "owner": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "git_url": "git://gitee.com:oschina/git-osc.git",
    "private": false,
    "ssh_url": "git@gitee.com:oschina/git-osc.git",
    "svn_url": "svn://gitee.com/oschina/git-osc",
    "has_wiki": true,
    "html_url": "https://gitee.com/oschina/git-osc",
    "language": "ruby",
    "clone_url": "https://gitee.com/oschina/git-osc.git",
    "full_name": "oschina/git-osc",
    "has_pages": false,
    "namespace": "oschina",
    "pushed_at": "2020-04-15T21:09:40+08:00",
    "created_at": "2020-04-15T21:09:40+08:00",
    "has_issues": true,
    "updated_at": "2020-04-15T21:09:40+08:00",
    "description": "",
    "forks_count": 0,
    "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
    "git_svn_url": "svn://gitee.com/oschina/git-osc",
    "git_http_url": "https://gitee.com/oschina/git-osc.git",
    "default_branch": "master",
    "watchers_count": 12,
    "stargazers_count": 11,
    "open_issues_count": 0,
    "name_with_namespace": "OSCHINA/git-osc",
    "path_with_namespace": "oschina/git-osc"
  },
  "assignee": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "email": "gitee@gitee.com",
    "username": "oschina-org",
    "user_name": "oschina-org"
  },
  "hook_url": "http://175.178.105.150:9088/",
  "password": "123123123",
  "hook_name": "issue_hooks",
  "milestone": "问题反馈",
  "enterprise": {
    "url": "https://gitee.com/oschina",
    "name": "OSCHINA"
  },
  "repository": {
    "id": 151,
    "url": "https://gitee.com/oschina/git-osc",
    "fork": false,
    "name": "Gitee FeedBack",
    "path": "git-osc",
    "owner": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "git_url": "git://gitee.com:oschina/git-osc.git",
    "private": false,
    "ssh_url": "git@gitee.com:oschina/git-osc.git",
    "svn_url": "svn://gitee.com/oschina/git-osc",
    "has_wiki": true,
    "html_url": "https://gitee.com/oschina/git-osc",
    "language": "ruby",
    "clone_url": "https://gitee.com/oschina/git-osc.git",
    "full_name": "oschina/git-osc",
    "has_pages": false,
    "namespace": "oschina",
    "pushed_at": "2020-04-15T21:09:40+08:00",
    "created_at": "2020-04-15T21:09:40+08:00",
    "has_issues": true,
    "updated_at": "2020-04-15T21:09:40+08:00",
    "description": "",
    "forks_count": 0,
    "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
    "git_svn_url": "svn://gitee.com/oschina/git-osc",
    "git_http_url": "https://gitee.com/oschina/git-osc.git",
    "default_branch": "master",
    "watchers_count": 12,
    "stargazers_count": 11,
    "open_issues_count": 0,
    "name_with_namespace": "OSCHINA/git-osc",
    "path_with_namespace": "oschina/git-osc"
  },
  "updated_by": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "email": "gitee@gitee.com",
    "username": "oschina-org",
    "user_name": "oschina-org"
  },
  "description": "这是一条测试 WebHook 接收功能触发的推送",
  "target_user": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "email": "gitee@gitee.com",
    "username": "oschina-org",
    "user_name": "oschina-org"
  }
}
`

func TestExtractIssueHookAttr(t *testing.T) {
	attrList, err := ExtractIssueHookAttr([]byte(_ISSUE_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
